package edu.pku.sei.ocl.value;

import org.eclipse.emf.common.util.BasicEMap;
import org.eclipse.emf.ecore.EClassifier;

import edu.pku.sei.ocl.utilities.OCLConstant;
import edu.pku.sei.ocl.utilities.OCLStandardLibrary;

public class OCLTuple extends BasicEMap<String, Object>{

	public String[] keyNames;
	public EClassifier[] valueOclTypes;
	
	public OCLTuple(String[] strings,EClassifier[] classifiers){
		keyNames = strings;
		valueOclTypes = classifiers;
		for(String str:keyNames){
			put(str,OCLConstant.OCLUninited);
		}
	}

	public OCLTuple(OCLTuple source) {
		keyNames = source.keyNames;
		valueOclTypes = source.valueOclTypes;
		for(String str:keyNames){
			put(str,source.get(str));
		}
	}

	@Override
	public Object put(String key, Object value) {
		//fix me : check type
		return super.put(key, value);
	}
	
	public boolean equals(Object r){	
		if(OCLStandardLibrary.oclType(this)==OCLStandardLibrary.oclType(r)){
			OCLTuple tr = (OCLTuple)r;
			for(String k : keyNames){
				if(OCLStandardLibrary.isTrue(OCLStandardLibrary.equal(get(k), tr.get(k)))==false)
					return false;
			}
			return true;
		}
		return false;
		
	}
}
